package com.empire.module.sporttery.controller.admin.football500hot;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.sporttery.controller.admin.football500hot.vo.*;
import com.empire.module.sporttery.dal.dataobject.football500hot.Football500HotDO;
import com.empire.module.sporttery.service.football500hot.Football500HotService;

@Tag(name = "管理后台 - 热度分析明细")
@RestController
@RequestMapping("/sporttery/football500-hot")
@Validated
public class Football500HotController {

    @Resource
    private Football500HotService football500HotService;

    @PostMapping("/create")
    @Operation(summary = "创建热度分析明细")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-hot:create')")
    public CommonResult<Integer> createFootball500Hot(@Valid @RequestBody Football500HotSaveReqVO createReqVO) {
        return success(football500HotService.createFootball500Hot(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新热度分析明细")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-hot:update')")
    public CommonResult<Boolean> updateFootball500Hot(@Valid @RequestBody Football500HotSaveReqVO updateReqVO) {
        football500HotService.updateFootball500Hot(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除热度分析明细")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('sporttery:football500-hot:delete')")
    public CommonResult<Boolean> deleteFootball500Hot(@RequestParam("id") Integer id) {
        football500HotService.deleteFootball500Hot(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得热度分析明细")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-hot:query')")
    public CommonResult<Football500HotRespVO> getFootball500Hot(@RequestParam("id") Integer id) {
        Football500HotDO football500Hot = football500HotService.getFootball500Hot(id);
        return success(BeanUtils.toBean(football500Hot, Football500HotRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得热度分析明细分页")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-hot:query')")
    public CommonResult<PageResult<Football500HotRespVO>> getFootball500HotPage(@Valid Football500HotPageReqVO pageReqVO) {
        PageResult<Football500HotDO> pageResult = football500HotService.getFootball500HotPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Football500HotRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出热度分析明细 Excel")
    @PreAuthorize("@ss.hasPermission('sporttery:football500-hot:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFootball500HotExcel(@Valid Football500HotPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Football500HotDO> list = football500HotService.getFootball500HotPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "热度分析明细.xls", "数据", Football500HotRespVO.class,
                        BeanUtils.toBean(list, Football500HotRespVO.class));
    }

}